package cn.zhf.shop.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.zhf.shop.config.GlobalConfig;
import cn.zhf.shop.entity.*;
import cn.zhf.shop.entity.count.*;
import cn.zhf.shop.entity.lesson.Lesson;
import cn.zhf.shop.entity.lesson.LessonType;
import cn.zhf.shop.entity.organization.Organization;
import cn.zhf.shop.mapper.*;
import cn.zhf.shop.sdk.DemoBase;
import cn.zhf.shop.service.CountService;
import cn.zhf.shop.utils.CountOrdersNumberByDays;
import cn.zhf.shop.utils.GetEveryDate;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Component
public class CountServiceImpl implements CountService {
    @Resource
    private CountAgeByCamMapper countAgeByCamMapper;
    @Resource
    private CountEduByCamMapper countEduByCamMapper;
    @Resource
    private SumByCamMapper sumByCamMapper;
    @Resource
    private SumByOrgMapper sumByOrgMapper;
    @Resource
    private ClassUserMapper classUserMapper;
    @Resource
    private OrdersMapper ordersMapper;
    @Resource
    private StageMapper stageMapper;
    @Resource
    private OrganizationMapper organizationMapper;
    @Resource
    private CampusMapper campusMapper;
    @Resource
    private LessonMapper lessonMapper;
    @Resource
    private GlobalConfig globalConfig;
    @Resource
    private LessonTypeMapper lessonTypeMapper;
    @Resource
    private ConsoleUserMapper consoleUserMapper;
    @Resource
    private RebateLevelMapper rebateLevelMapper;


    @Override
    public Message<List<CountEduByCam>> countAllEduByCam() {
        return Message.success(null).add(countEduByCamMapper.selectAll());
    }

    @Override
    public Message<CountEduByCam> countEduByCam(int camId) {
        return Message.success(null).add(countEduByCamMapper.selectAllByCamId(camId));
    }

    @Override
    public Message<List<CountAgeByCam>> countAllAgeByCam() {
        return Message.success(null).add(countAgeByCamMapper.selectAll());
    }

    @Override
    public Message<CountAgeByCam> countAgeByCam(int camId) {
        return Message.success(null).add(countAgeByCamMapper.selectAllByCamId(camId));
    }

    @Override
    public Message<List<SumByCam>> sumAllByCam() {



        return Message.success(null).add(sumByCamMapper.selectAll());
    }

    @Override
    public Message<SumByCam> sumByCam(int camId) {
        return Message.success(null).add(sumByCamMapper.selectAllByCamId(camId));
    }

    @Override
    public Message<List<SumByOrg>> sumAllByOrg() {
        return Message.success(null).add(sumByOrgMapper.selectAll());
    }

    @Override
    public Message<SumByOrg> sumByOrg(int orgId) {
        return Message.success(null).add(sumByOrgMapper.selectAllByOrgId(orgId));
    }

    @Override
    public Message<List<SumByCam>> sumAllByCamS() {
        return Message.success(null).add(sumByCamMapper.selectAllS());
    }

    @Override
    public Message<SumByCam> sumByCamS(int camId) {
        return Message.success(null).add(sumByCamMapper.selectAllByCamIdS(camId));
    }

    @Override
    public Message<List<SumByOrg>> sumAllByOrgS() {
        return Message.success(null).add(sumByOrgMapper.selectAllS());
    }

    @Override
    public Message<SumByOrg> sumByOrgS(int orgId) {
        return Message.success(null).add(sumByOrgMapper.selectAllByOrgIdS(orgId));
    }

    @Override
    public Message<List<SumByCam>> sumAllByCamNS() {
        return Message.success(null).add(sumByCamMapper.selectAllNS());
    }

    @Override
    public Message<SumByCam> sumByCamNS(int camId) {
        return Message.success(null).add(sumByCamMapper.selectAllByCamIdNS(camId));
    }

    @Override
    public Message<List<SumByOrg>> sumAllByOrgNS() {
        return Message.success(null).add(sumByOrgMapper.selectAllNS());
    }

    @Override
    public Message<SumByOrg> sumByOrgNS(int orgId) {
        return Message.success(null).add(sumByOrgMapper.selectAllByOrgIdNS(orgId));
    }

    @Override
    public Message<HashMap> countAll() {
        HashMap refund=new HashMap();

        int Snumber=0;
        int NSnumber=0;
        int price=0;
        int totalOrdersAll = 0;
        List<Orders> ordersList = ordersMapper.selectByState(1);
        for (int i=0;i<ordersList.size();i++)
        {
            String orderId = ordersList.get(i).getId();
            if (stageMapper.selectByOrderId(orderId)!=null) {
                Snumber++;
            }
            else
            {
                NSnumber++;
            }
            totalOrdersAll++;
            price=ordersList.get(i).getTotalPrice().intValue()+price;

        }



        refund.put("totalUser",classUserMapper.countUser());
        refund.put("totalOrdersAll",totalOrdersAll);
        refund.put("totalOrdersStage",Snumber);
        refund.put("totalOrdersNotStage",NSnumber);
        refund.put("totalOrdersPrice",price);

        return Message.success("总用户量").add(refund);
    }


    /**
     * 图表统计
     * 1234分别是周月季年
     * orderId和campusId为空的值为-999
     * 查看当前日期所在周的所有订单 例；2020-09-17
     * 月的话传一个时间默认当前天 例；2020-09-01
     * 季度的话传一个时间 例；2020-01-01 2020-04-01 2020-07-01 2020-10-01
     * 年的的话传一个时间 例；2020-01-01
     *
     * @return
     */

    public Message countchart(CountNumbers countNumbers) throws ParseException {

        int orgId = countNumbers.getOrgId();
        int campusId = countNumbers.getCampusId();
        int timetype = countNumbers.getTimetype();

        String searchdate = countNumbers.getSearchdate();



        CountOders countOders = new CountOders();
        if (searchdate!=null)
        {
            SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(searchdate);
            countOders.setDate(date);
        }else {
            countOders.setDate(new Date());
        }

        if (countNumbers.getCountType()==null)
        {
            //接口什么都没传，就返回所有的机构，如[‘求道科技’,’红黄蓝学校’……]
        if (orgId==-999)
        {
            if (campusId==-999)
            {
                //获得所有机构名称
                List<Organization> organizationList = organizationMapper.selectAll();
                List<String> orgNameList = new LinkedList<>();
                for (int i=0;i<organizationList.size();i++)
                {
                    orgNameList.add(organizationList.get(i).getOrgName());
                }


                //1是周
                if (timetype==1)
                {


                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);

                    //一周的所有时间
                    List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                    SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");


                    //查询每个机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<orgNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setOrgName(orgNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInWeeK(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(orgNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa = new CountDa();
                    countDa.setNameList(orgNameList);
                    countDa.setDateList(dateList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);


                    countDa.setOrdersList(ordersList);

                    return Message.success(null).add(countDa);

                }
                //2是月
                else if (timetype==2)
                {


                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    //本月的所有时间
                    List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());
                    SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");


                    //查询每个机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<orgNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setOrgName(orgNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInMonth(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(orgNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(orgNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }
                //3是季
                else if (timetype==3)
                {
                    //一季的所有时间
                   List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());

                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);

                    //查询每个机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<orgNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setOrgName(orgNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInQuarter(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(orgNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(orgNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);

                }
                //4是年
                else if (timetype==4)
                {
                    //一年的所有时间
                    List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());


                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    //查询每个机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<orgNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setOrgName(orgNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInYear(countOders);

                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(orgNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(orgNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }

            }
        }

        //传了机构id（orgId），返回该机构下的分支机构
        else if (orgId!=-999)
        {
            if (campusId==-999)
            {
                List<Campus> campusList = campusMapper.selectByOrgId(orgId);
                //1是周
                if (timetype==1)
                {
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());

                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);


                    //查询所有分支机构名称
                    List<String> capmusNameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        String campusName= campusList.get(i).getCampusName();
                        capmusNameList.add(campusName);
                    }


                    //一周的所有时间
                    List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                    SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
                    Date rdate = simpleDateFormat.parse(dateList.get(6));


                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<capmusNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(capmusNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInWeeK(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(capmusNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa = new CountDa();
                    countDa.setNameList(capmusNameList);
                    countDa.setDateList(dateList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);
                    countDa.setOrdersList(ordersList);

                    return Message.success(null).add(countDa);

                }
                //2是月
                else if (timetype==2)
                {
                    //查询所有分支机构名称
                    List<String> capmusNameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        String campusName= campusList.get(i).getCampusName();
                        capmusNameList.add(campusName);
                    }
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());


                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);


                    //本月的所有时间
                    List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());

                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<capmusNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(capmusNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInMonth(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(capmusNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(capmusNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }
                //3是季
                else if (timetype==3)
                {
                    //查询所有分支机构名称
                    List<String> capmusNameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        String campusName= campusList.get(i).getCampusName();
                        capmusNameList.add(campusName);
                    }
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());


                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    //本季度的所有时间
                    List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());

                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<capmusNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(capmusNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInQuarter(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(capmusNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(capmusNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }
                //4是年
                else if (timetype==4)
                {
                    //查询所有分支机构名称
                    List<String> capmusNameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        String campusName= campusList.get(i).getCampusName();
                        capmusNameList.add(campusName);
                    }
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());


                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    //本年度的所有时间
                    List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());

                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<capmusNameList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(capmusNameList.get(i));
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInYear(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(capmusNameList.get(i));
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(capmusNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }

            }

            //传了orgId和campusId，返回该分支机构的所有服务项目
            if (campusId!=-999)
            {
                List<Lesson> lessonList = lessonMapper.selectByCampus(campusId);

                //1是周
                if (timetype==1)
                {

                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInWeeKInCampus(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    //查询所有服务名称
                    List<String> LessonNameList = new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        String campusName= lessonList.get(i).getLessonName();
                        LessonNameList.add(campusName);
                    }


                    //一周的所有时间
                    List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                    SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
                    Date rdate = simpleDateFormat.parse(dateList.get(6));

                    //查询每个服务的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setLessonId(lessonList.get(i).getLessonId());
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInWeeKByLessonId(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(lessonList.get(i).getLessonName());
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa = new CountDa();
                    countDa.setNameList(LessonNameList);
                    countDa.setDateList(dateList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);
                    countDa.setOrdersList(ordersList);

                    return Message.success(null).add(countDa);
                }
                //2是月
                else if (timetype==2)
                {
                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInWeeKInCampus(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    //查询所有服务名称
                    List<String> LessonNameList = new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        String campusName= lessonList.get(i).getLessonName();
                        LessonNameList.add(campusName);
                    }

                    //本月的所有时间
                    List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());

                    //查询每个服务的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setLessonId(lessonList.get(i).getLessonId());
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInMonthLesson(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(lessonList.get(i).getLessonName());
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(LessonNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }
                //3是季
                else if (timetype==3)
                {
                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());


                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);

                    //查询所有服务名称
                    List<String> LessonNameList = new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        String campusName= lessonList.get(i).getLessonName();
                        LessonNameList.add(campusName);
                    }

                    //本月的所有时间
                    List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());

                    //查询每个服务的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setLessonId(lessonList.get(i).getLessonId());
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInQuarterLesson(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(lessonList.get(i).getLessonName());
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(LessonNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }
                //4是年
                else if (timetype==4)
                {
                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    //查询所有服务名称
                    List<String> LessonNameList = new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        String campusName= lessonList.get(i).getLessonName();
                        LessonNameList.add(campusName);
                    }

                    //本月的所有时间
                    List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());

                    //查询每个服务的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (int i=0;i<lessonList.size();i++)
                    {
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setLessonId(lessonList.get(i).getLessonId());
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInYearLesson(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(lessonList.get(i).getLessonName());
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    CountDa countDa =new CountDa();
                    countDa.setOrdersList(ordersList);
                    countDa.setDateList(dateList);
                    countDa.setNameList(LessonNameList);
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }

            }
        }
        }
        else if (countNumbers.getCountType()==2||countNumbers.getCountType()==3)
        {
            //接口什么都没传，就返回所有的机构，如[‘求道科技’,’红黄蓝学校’……]
            if (orgId==-999)
            {
                if (campusId==-999)
                {
                    //获得所有机构名称
                    List<Organization> organizationList = organizationMapper.selectAll();
                    List<String> orgNameList = new LinkedList<>();
                    for (int i=0;i<organizationList.size();i++)
                    {
                        orgNameList.add(organizationList.get(i).getOrgName());
                    }


                    //1是周
                    if (timetype==1)
                    {


                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);

                        //一周的所有时间
                        List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                        SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");


                        //查询每个机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<orgNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setOrgName(orgNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInWeeK(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                            List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(orgNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa = new CountDa();
                        countDa.setNameList(orgNameList);
                        countDa.setDateList(dateList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);


                        countDa.setOrdersList(ordersList);

                        return Message.success(null).add(countDa);

                    }
                    //2是月
                    else if (timetype==2)
                    {


                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                        //本月的所有时间
                        List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());
                        SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");


                        //查询每个机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<orgNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setOrgName(orgNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInMonth(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                            List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(orgNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(orgNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }
                    //3是季
                    else if (timetype==3)
                    {
                        //一季的所有时间
                        List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());

                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }
                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);

                        //查询每个机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<orgNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setOrgName(orgNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInQuarter(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                            List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(orgNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(orgNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);

                    }
                    //4是年
                    else if (timetype==4)
                    {
                        //一年的所有时间
                        List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());


                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                        //查询每个机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<orgNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setOrgName(orgNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInYear(countOders);

                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(orgNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(orgNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }

                }
            }

            //传了机构id（orgId），返回该机构下的分支机构
            else if (orgId!=-999&&orgId!=-777)
            {
                if (campusId==-999)
                {
                    List<Campus> campusList = campusMapper.selectByOrgId(orgId);
                    //1是周
                    if (timetype==1)
                    {
                        countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());

                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);


                        //查询所有分支机构名称
                        List<String> capmusNameList = new LinkedList<>();
                        for (int i=0;i<campusList.size();i++)
                        {
                            String campusName= campusList.get(i).getCampusName();
                            capmusNameList.add(campusName);
                        }


                        //一周的所有时间
                        List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                        SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
                        Date rdate = simpleDateFormat.parse(dateList.get(6));


                        //查询每个分支机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<capmusNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setCampusName(capmusNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInWeeK(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                            List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(capmusNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa = new CountDa();
                        countDa.setNameList(capmusNameList);
                        countDa.setDateList(dateList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);
                        countDa.setOrdersList(ordersList);

                        return Message.success(null).add(countDa);

                    }
                    //2是月
                    else if (timetype==2)
                    {
                        //查询所有分支机构名称
                        List<String> capmusNameList = new LinkedList<>();
                        for (int i=0;i<campusList.size();i++)
                        {
                            String campusName= campusList.get(i).getCampusName();
                            capmusNameList.add(campusName);
                        }
                        countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());


                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }
                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);


                        //本月的所有时间
                        List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());

                        //查询每个分支机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<capmusNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setCampusName(capmusNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInMonth(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(capmusNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(capmusNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }
                    //3是季
                    else if (timetype==3)
                    {
                        //查询所有分支机构名称
                        List<String> capmusNameList = new LinkedList<>();
                        for (int i=0;i<campusList.size();i++)
                        {
                            String campusName= campusList.get(i).getCampusName();
                            capmusNameList.add(campusName);
                        }
                        countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());


                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }
                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                        //本季度的所有时间
                        List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());

                        //查询每个分支机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<capmusNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setCampusName(capmusNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInQuarter(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(capmusNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(capmusNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }
                    //4是年
                    else if (timetype==4)
                    {
                        //查询所有分支机构名称
                        List<String> capmusNameList = new LinkedList<>();
                        for (int i=0;i<campusList.size();i++)
                        {
                            String campusName= campusList.get(i).getCampusName();
                            capmusNameList.add(campusName);
                        }
                        countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());


                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                        //本年度的所有时间
                        List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());

                        //查询每个分支机构的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<capmusNameList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setCampusName(capmusNameList.get(i));
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInYear(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(capmusNameList.get(i));
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(capmusNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }

                }

                //传了orgId和campusId，返回该分支机构的所有服务项目
                if (campusId!=-999&&campusId!=-777)
                {
                    List<Lesson> lessonList = lessonMapper.selectByCampus(campusId);

                    //1是周
                    if (timetype==1)
                    {

                        countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInWeeKInCampus(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);


                        //查询所有服务名称
                        List<String> LessonNameList = new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            String campusName= lessonList.get(i).getLessonName();
                            LessonNameList.add(campusName);
                        }


                        //一周的所有时间
                        List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                        SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
                        Date rdate = simpleDateFormat.parse(dateList.get(6));

                        //查询每个服务的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setLessonId(lessonList.get(i).getLessonId());
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInWeeKByLessonId(countOders);

                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(lessonList.get(i).getLessonName());
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa = new CountDa();
                        countDa.setNameList(LessonNameList);
                        countDa.setDateList(dateList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);
                        countDa.setOrdersList(ordersList);

                        return Message.success(null).add(countDa);
                    }
                    //2是月
                    else if (timetype==2)
                    {
                        countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInWeeKInCampus(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                        //查询所有服务名称
                        List<String> LessonNameList = new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            String campusName= lessonList.get(i).getLessonName();
                            LessonNameList.add(campusName);
                        }

                        //本月的所有时间
                        List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());

                        //查询每个服务的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setLessonId(lessonList.get(i).getLessonId());
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInMonthLesson(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(lessonList.get(i).getLessonName());
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(LessonNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }
                    //3是季
                    else if (timetype==3)
                    {
                        countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());


                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);

                        //查询所有服务名称
                        List<String> LessonNameList = new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            String campusName= lessonList.get(i).getLessonName();
                            LessonNameList.add(campusName);
                        }

                        //本月的所有时间
                        List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());

                        //查询每个服务的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setLessonId(lessonList.get(i).getLessonId());
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInQuarterLesson(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(lessonList.get(i).getLessonName());
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(LessonNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }
                    //4是年
                    else if (timetype==4)
                    {
                        countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                        //查询到的所有订单
                        List<Orders> ordersList2 = new LinkedList<>();
                        List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                        if (ordersList1!=null)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }
                        List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                        //查询所有服务名称
                        List<String> LessonNameList = new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            String campusName= lessonList.get(i).getLessonName();
                            LessonNameList.add(campusName);
                        }

                        //本月的所有时间
                        List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());

                        //查询每个服务的订单数量
                        List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                        for (int i=0;i<lessonList.size();i++)
                        {
                            CountOrgOrders countOrgOrders = new CountOrgOrders();
                            countOders.setLessonId(lessonList.get(i).getLessonId());
                            List<Orders> OrgOrdersList1 = ordersMapper.selectInYearLesson(countOders);
                            List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);

                            List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);
                            countOrgOrders.setData(integerList);
                            countOrgOrders.setType("line");
                            countOrgOrders.setName(lessonList.get(i).getLessonName());
                            countOrgOrdersList.add(countOrgOrders);
                        }
                        CountDa countDa =new CountDa();
                        countDa.setOrdersList(ordersList);
                        countDa.setDateList(dateList);
                        countDa.setNameList(LessonNameList);
                        countDa.setCountOrgOrdersList(countOrgOrdersList);

                        return Message.success(null).add(countDa);
                    }

                }
            }

            else if (orgId==-777&&campusId==-777){
                CountDa countDa = new CountDa();

                if (timetype==1){


                    //获得名字
                    List<Campus> campusList = campusMapper.selectAll();
                    List<String> NameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        NameList.add(campusList.get(i).getCampusName());
                    }
                    countDa.setNameList(NameList);

                    //一周的所有时间
                    List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                    countDa.setDateList(dateList);

                    //获得所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    countDa.setOrdersList(ordersList);


                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (String campusName:NameList){
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(campusName);
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInWeeK(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);

                        countOrgOrders.setData(integerList);
                        countOrgOrders.setName(campusName);
                        countOrgOrders.setType("line");
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    countDa.setCountOrgOrdersList(countOrgOrdersList);
                    return Message.success(null).add(countDa);



                }
                else if (timetype==2){

                    //获得名字
                    List<Campus> campusList = campusMapper.selectAll();
                    List<String> NameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        NameList.add(campusList.get(i).getCampusName());
                    }
                    countDa.setNameList(NameList);

                    //一月的所有时间
                    List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());
                    countDa.setDateList(dateList);

                    //获得所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    countDa.setOrdersList(ordersList);


                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (String campusName:NameList){
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(campusName);
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInMonth(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,OrgOrdersList);

                        countOrgOrders.setData(integerList);
                        countOrgOrders.setName(campusName);
                        countOrgOrders.setType("line");
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    countDa.setCountOrgOrdersList(countOrgOrdersList);
                    return Message.success(null).add(countDa);


                }else if (timetype==3){
                    //获得名字
                    List<Campus> campusList = campusMapper.selectAll();
                    List<String> NameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        NameList.add(campusList.get(i).getCampusName());
                    }
                    countDa.setNameList(NameList);

                    //一季度的所有时间
                    List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());
                    countDa.setDateList(dateList);

                    //获得所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    countDa.setOrdersList(ordersList);


                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (String campusName:NameList){
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(campusName);
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInQuarter(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);

                        countOrgOrders.setData(integerList);
                        countOrgOrders.setName(campusName);
                        countOrgOrders.setType("line");
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    countDa.setCountOrgOrdersList(countOrgOrdersList);
                    return Message.success(null).add(countDa);
                }else if (timetype==4){
                    //获得名字
                    List<Campus> campusList = campusMapper.selectAll();
                    List<String> NameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        NameList.add(campusList.get(i).getCampusName());
                    }
                    countDa.setNameList(NameList);

                    //一月的所有时间
                    List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());
                    countDa.setDateList(dateList);

                    //获得所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    countDa.setOrdersList(ordersList);


                    //查询每个分支机构的订单数量
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (String campusName:NameList){
                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        countOders.setCampusName(campusName);
                        List<Orders> OrgOrdersList1 = ordersMapper.selectInYear(countOders);
                        List<Orders> OrgOrdersList =ScreenByAgeAndPriceAndPayType(OrgOrdersList1,countNumbers);
                        List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,OrgOrdersList);

                        countOrgOrders.setData(integerList);
                        countOrgOrders.setName(campusName);
                        countOrgOrders.setType("line");
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    countDa.setCountOrgOrdersList(countOrgOrdersList);
                    return Message.success(null).add(countDa);
                }
            }



        }
        else if (countNumbers.getCountType()==1||countNumbers.getCountType()==4)
        {
            return Admincountchart(countNumbers);
        }

       return Message.fail(null);
    }

    /**
     * 机构类别，机构，分支机构，服务项目
     * 1234分别是周月季年
     * @param countNumbers
     * @return
     * @throws ParseException
     */

    public Message Admincountchart(CountNumbers countNumbers) throws ParseException {

        CountDa countDa = new CountDa();
        if (countNumbers.getCountType()!=null)
        {
                /**
                 * 周
                 */
                if (countNumbers.getTimetype()==1){
                    return AdmincountchartInWeek(countNumbers);
                }

                /**
                 * 月
                 */
                else if (countNumbers.getTimetype()==2){
                    return AdmincountchartInMonth(countNumbers);
                }

                /**
                 * 季度
                 */
                else if (countNumbers.getTimetype()==3){
                    return AdmincountchartInQuarter(countNumbers);
                }

                /**
                 * 年
                 */
                else if (countNumbers.getTimetype()==4){
                    return AdmincountchartInYear(countNumbers);
                }

        }


        return Message.success(null).add(countDa);











    }

    public Message AdmincountchartInYear(CountNumbers countNumbers) throws ParseException{
        String searchdate = countNumbers.getSearchdate();
        CountOders countOders = new CountOders();
        if (searchdate!=null)
        {
            SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(searchdate);
            countOders.setDate(date);
        }else {
            countOders.setDate(new Date());
        }
        CountDa countDa = new CountDa();
        //机构类别
        if (countNumbers.getCountType()==1){
            //所有机构类别
            if (countNumbers.getCountId()==null){

                /**
                 * 获得名字
                 */
                List<LessonType> lessonTypes = lessonTypeMapper.selectAll();
                List<String> namelist = new LinkedList<>();
                for (LessonType lessonType:lessonTypes){
                    namelist.add(lessonType.getTypeName());
                }
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList =GetEveryDate.getYearByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                if (ordersList1!=null)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                for (LessonType lessonType:lessonTypes){

                    CountOrgOrders countOrgOrders = new CountOrgOrders();
                    List<Orders> ordersList3 = new LinkedList<>();
                    for (Orders orders:ordersList){
                        Organization organization = organizationMapper.selectByOrgName(orders.getOrgName()).get(0);
                        if (organization.getOrgType()==lessonType.getId())
                            ordersList3.add(orders);
                    }

                    List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList3);

                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lessonType.getTypeName());
                    countOrgOrdersList.add(countOrgOrders);
                }
                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);

            }
            else if (countNumbers.getCountId()!=null){
                /**
                 * 获得名字
                 */
                LessonType lessonType =lessonTypeMapper.selectByPrimaryKey(countNumbers.getCountId());
                List<String> namelist = new LinkedList<>();
                namelist.add(lessonType.getTypeName());
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Organization> organizationList = organizationMapper.selectByOrgType2(lessonType.getId());

                for (Organization organization:organizationList)
                {
                    CountOders countOders1 = new CountOders();
                    countOders1.setOrgName(organization.getOrgName());
                    countOders1.setDate(countOders.getDate());

                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders1);

                    if (ordersList1.size()>0)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                }

                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();


                CountOrgOrders countOrgOrders = new CountOrgOrders();
                List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList);
                countOrgOrders.setData(integerList);
                countOrgOrders.setType("line");
                countOrgOrders.setName(lessonType.getTypeName());
                countOrgOrdersList.add(countOrgOrders);

                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
        }

        //服务项目
        else if (countNumbers.getCountType()==4){
            //所有服务项目
            if (countNumbers.getCountId()==null){
                /**
                 * 获得名字
                 */
                List<Lesson> lessonList = lessonMapper.selectAll();
                List<String> namelist = new LinkedList<>();
                for (Lesson lesson:lessonList){
                    namelist.add(lesson.getLessonName());
                }
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Orders> ordersList1 = ordersMapper.selectInYearLesson(countOders);
                if (ordersList1!=null)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                for (Lesson lesson:lessonList){

                    CountOrgOrders countOrgOrders = new CountOrgOrders();
                    List<Orders> ordersList3 = new LinkedList<>();
                    for (Orders orders:ordersList){

                        if (orders.getLessonId()==lesson.getLessonId())
                            ordersList3.add(orders);
                    }
                    List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList3);
                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lesson.getLessonName());
                    countOrgOrdersList.add(countOrgOrders);
                }
                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
            else if (countNumbers.getCountId()!=null){
                /**
                 * 获得名字
                 */
                List<String> namelist = new LinkedList<>();
                String name = lessonMapper.selectByPrimaryKey(countNumbers.getCountId()).getLessonName();
                namelist.add(name);
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getYearByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                countOders.setLessonId(countNumbers.getCountId());
                List<Orders> ordersList1 = ordersMapper.selectInYearLesson(countOders);
                if (ordersList1.size()>0)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                Lesson lesson = lessonMapper.selectByPrimaryKey(countNumbers.getCountId());

                CountOrgOrders countOrgOrders = new CountOrgOrders();


                List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList);
                countOrgOrders.setData(integerList);
                countOrgOrders.setType("line");
                countOrgOrders.setName(lesson.getLessonName());
                countOrgOrdersList.add(countOrgOrders);

                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
        }

        return null;
    }

    public Message AdmincountchartInQuarter(CountNumbers countNumbers) throws ParseException{
        String searchdate = countNumbers.getSearchdate();
        CountOders countOders = new CountOders();
        if (searchdate!=null)
        {
            SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(searchdate);
            countOders.setDate(date);
        }else {
            countOders.setDate(new Date());
        }
        CountDa countDa = new CountDa();
        //机构类别
        if (countNumbers.getCountType()==1){
            //所有机构类别
            if (countNumbers.getCountId()==null){

                /**
                 * 获得名字
                 */
                List<LessonType> lessonTypes = lessonTypeMapper.selectAll();
                List<String> namelist = new LinkedList<>();
                for (LessonType lessonType:lessonTypes){
                    namelist.add(lessonType.getTypeName());
                }
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList =GetEveryDate.getQuarterByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                if (ordersList1!=null)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                for (LessonType lessonType:lessonTypes){

                    CountOrgOrders countOrgOrders = new CountOrgOrders();
                    List<Orders> ordersList3 = new LinkedList<>();
                    for (Orders orders:ordersList){
                        Organization organization = organizationMapper.selectByOrgName(orders.getOrgName()).get(0);
                        if (organization.getOrgType()==lessonType.getId())
                            ordersList3.add(orders);
                    }
                    List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList3);
                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lessonType.getTypeName());
                    countOrgOrdersList.add(countOrgOrders);
                }
                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);

            }
            else if (countNumbers.getCountId()!=null){
                /**
                 * 获得名字
                 */
                LessonType lessonType =lessonTypeMapper.selectByPrimaryKey(countNumbers.getCountId());
                List<String> namelist = new LinkedList<>();
                namelist.add(lessonType.getTypeName());
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Organization> organizationList = organizationMapper.selectByOrgType2(lessonType.getId());

                for (Organization organization:organizationList)
                {
                    CountOders countOders1 = new CountOders();
                    countOders1.setOrgName(organization.getOrgName());
                    countOders1.setDate(countOders.getDate());
                    System.out.println("CountOders:"+countOders1);
                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders1);
                    System.out.println(ordersList1);
                    if (ordersList1.size()>0)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                }

                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();


                CountOrgOrders countOrgOrders = new CountOrgOrders();
                List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList);
                countOrgOrders.setData(integerList);
                countOrgOrders.setType("line");
                countOrgOrders.setName(lessonType.getTypeName());
                countOrgOrdersList.add(countOrgOrders);

                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
        }

        //服务项目
        else if (countNumbers.getCountType()==4){
            //所有服务项目
            if (countNumbers.getCountId()==null){
                /**
                 * 获得名字
                 */
                List<Lesson> lessonList = lessonMapper.selectAll();
                List<String> namelist = new LinkedList<>();
                for (Lesson lesson:lessonList){
                    namelist.add(lesson.getLessonName());
                }
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Orders> ordersList1 = ordersMapper.selectInQuarterLesson(countOders);
                if (ordersList1!=null)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                for (Lesson lesson:lessonList){

                    CountOrgOrders countOrgOrders = new CountOrgOrders();
                    List<Orders> ordersList3 = new LinkedList<>();
                    for (Orders orders:ordersList){

                        if (orders.getLessonId()==lesson.getLessonId())
                            ordersList3.add(orders);
                    }
                    List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList3);
                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lesson.getLessonName());
                    countOrgOrdersList.add(countOrgOrders);
                }
                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
            else if (countNumbers.getCountId()!=null){
                /**
                 * 获得名字
                 */
                List<String> namelist = new LinkedList<>();
                String name = lessonMapper.selectByPrimaryKey(countNumbers.getCountId()).getLessonName();
                namelist.add(name);
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                countOders.setLessonId(countNumbers.getCountId());
                List<Orders> ordersList1 = ordersMapper.selectInQuarterLesson(countOders);
                if (ordersList1.size()>0)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                Lesson lesson = lessonMapper.selectByPrimaryKey(countNumbers.getCountId());

                CountOrgOrders countOrgOrders = new CountOrgOrders();


                List<Integer> integerList =CountOrdersNumberByDays.getArrayMonth(dateList,ordersList);
                countOrgOrders.setData(integerList);
                countOrgOrders.setType("line");
                countOrgOrders.setName(lesson.getLessonName());
                countOrgOrdersList.add(countOrgOrders);

                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
        }

        return null;
    }

    public Message AdmincountchartInMonth(CountNumbers countNumbers) throws ParseException{
        String searchdate = countNumbers.getSearchdate();
        CountOders countOders = new CountOders();
        if (searchdate!=null)
        {
            SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(searchdate);
            countOders.setDate(date);
        }else {
            countOders.setDate(new Date());
        }
        CountDa countDa = new CountDa();
        //机构类别
        if (countNumbers.getCountType()==1){
            //所有机构类别
            if (countNumbers.getCountId()==null){

                /**
                 * 获得名字
                 */
                List<LessonType> lessonTypes = lessonTypeMapper.selectAll();
                List<String> namelist = new LinkedList<>();
                for (LessonType lessonType:lessonTypes){
                    namelist.add(lessonType.getTypeName());
                }
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList =GetEveryDate.getDayByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                if (ordersList1!=null)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                for (LessonType lessonType:lessonTypes){

                    CountOrgOrders countOrgOrders = new CountOrgOrders();
                    List<Orders> ordersList3 = new LinkedList<>();
                    for (Orders orders:ordersList){
                        Organization organization = organizationMapper.selectByOrgName(orders.getOrgName()).get(0);
                        if (organization.getOrgType()==lessonType.getId())
                            ordersList3.add(orders);
                    }
                    List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList3);
                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lessonType.getTypeName());
                    countOrgOrdersList.add(countOrgOrders);
                }
                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);

            }
            else if (countNumbers.getCountId()!=null){
                /**
                 * 获得名字
                 */
                LessonType lessonType =lessonTypeMapper.selectByPrimaryKey(countNumbers.getCountId());
                List<String> namelist = new LinkedList<>();
                namelist.add(lessonType.getTypeName());
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Organization> organizationList = organizationMapper.selectByOrgType2(lessonType.getId());

                for (Organization organization:organizationList)
                {
                    CountOders countOders1 = new CountOders();
                    countOders1.setOrgName(organization.getOrgName());
                    countOders1.setDate(countOders.getDate());
                    System.out.println("CountOders:"+countOders1);
                    List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders1);
                    System.out.println(ordersList1);
                    if (ordersList1.size()>0)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }

                }

                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();


                CountOrgOrders countOrgOrders = new CountOrgOrders();
                List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList);
                countOrgOrders.setData(integerList);
                countOrgOrders.setType("line");
                countOrgOrders.setName(lessonType.getTypeName());
                countOrgOrdersList.add(countOrgOrders);

                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
        }

        //服务项目
        else if (countNumbers.getCountType()==4){
            //所有服务项目
            if (countNumbers.getCountId()==null){
                /**
                 * 获得名字
                 */
                List<Lesson> lessonList = lessonMapper.selectAll();
                List<String> namelist = new LinkedList<>();
                for (Lesson lesson:lessonList){
                    namelist.add(lesson.getLessonName());
                }
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                if (ordersList1!=null)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                for (Lesson lesson:lessonList){

                    CountOrgOrders countOrgOrders = new CountOrgOrders();
                    List<Orders> ordersList3 = new LinkedList<>();
                    for (Orders orders:ordersList){

                        if (orders.getLessonId()==lesson.getLessonId())
                            ordersList3.add(orders);
                    }
                    List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList3);
                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lesson.getLessonName());
                    countOrgOrdersList.add(countOrgOrders);
                }
                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
            else if (countNumbers.getCountId()!=null){
                /**
                 * 获得名字
                 */
                List<String> namelist = new LinkedList<>();
                String name = lessonMapper.selectByPrimaryKey(countNumbers.getCountId()).getLessonName();
                namelist.add(name);
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.getDayByMonth(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                countOders.setLessonId(countNumbers.getCountId());
                List<Orders> ordersList1 = ordersMapper.selectInMonthLesson(countOders);
                if (ordersList1.size()>0)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                Lesson lesson = lessonMapper.selectByPrimaryKey(countNumbers.getCountId());

                CountOrgOrders countOrgOrders = new CountOrgOrders();


                List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList);
                countOrgOrders.setData(integerList);
                countOrgOrders.setType("line");
                countOrgOrders.setName(lesson.getLessonName());
                countOrgOrdersList.add(countOrgOrders);

                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
        }

        return null;
    }

    public Message AdmincountchartInWeek(CountNumbers countNumbers) throws ParseException{
        String searchdate = countNumbers.getSearchdate();
        CountOders countOders = new CountOders();
        if (searchdate!=null)
        {
            SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(searchdate);
            countOders.setDate(date);
        }else {
            countOders.setDate(new Date());
        }
        CountDa countDa = new CountDa();
        //机构类别
        if (countNumbers.getCountType()==1){
                //所有机构类别
                if (countNumbers.getCountId()==null){

                    /**
                     * 获得名字
                     */
                    List<LessonType> lessonTypes = lessonTypeMapper.selectAll();
                    List<String> namelist = new LinkedList<>();
                    for (LessonType lessonType:lessonTypes){
                        namelist.add(lessonType.getTypeName());
                    }
                    countDa.setNameList(namelist);


                    /**
                     * 获得时间
                     * 一周的所有时间
                     */
                    List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                    countDa.setDateList(dateList);

                    /**
                     * 查询所有订单
                     */
                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList2.add(orders);

                        }
                    }
                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    countDa.setOrdersList(ordersList);




                    /**
                     * 获得所有订单成交量
                     */
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                    for (LessonType lessonType:lessonTypes){

                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        List<Orders> ordersList3 = new LinkedList<>();
                        for (Orders orders:ordersList){
                            Organization organization = organizationMapper.selectByOrgName(orders.getOrgName()).get(0);
                            if (organization.getOrgType()==lessonType.getId())
                                ordersList3.add(orders);
                        }
                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList3);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(lessonType.getTypeName());
                        countOrgOrdersList.add(countOrgOrders);
                    }
                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);

                }
                else if (countNumbers.getCountId()!=null){
                    /**
                     * 获得名字
                     */
                    LessonType lessonType =lessonTypeMapper.selectByPrimaryKey(countNumbers.getCountId());
                    List<String> namelist = new LinkedList<>();
                    namelist.add(lessonType.getTypeName());
                    countDa.setNameList(namelist);


                    /**
                     * 获得时间
                     * 一周的所有时间
                     */
                    List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                    countDa.setDateList(dateList);

                    /**
                     * 查询所有订单
                     */
                    //查询到的所有订单
                    List<Orders> ordersList2 = new LinkedList<>();
                    List<Organization> organizationList = organizationMapper.selectByOrgType2(lessonType.getId());

                    for (Organization organization:organizationList)
                    {
                        CountOders countOders1 = new CountOders();
                        countOders1.setOrgName(organization.getOrgName());
                        countOders1.setDate(countOders.getDate());

                        List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders1);

                        if (ordersList1.size()>0)
                        {
                            for(int i=0;i<ordersList1.size();i++)
                            {
                                Orders orders = ordersList1.get(i);
                                if (orders.getLessonId()==-1)
                                {
                                    orders.setLessonName("线下支付");
                                }
                                else
                                    orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                                ordersList2.add(orders);

                            }
                        }

                    }

                    List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                    countDa.setOrdersList(ordersList);




                    /**
                     * 获得所有订单成交量
                     */
                    List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();


                        CountOrgOrders countOrgOrders = new CountOrgOrders();
                        List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList);
                        countOrgOrders.setData(integerList);
                        countOrgOrders.setType("line");
                        countOrgOrders.setName(lessonType.getTypeName());
                        countOrgOrdersList.add(countOrgOrders);

                    countDa.setCountOrgOrdersList(countOrgOrdersList);

                    return Message.success(null).add(countDa);
                }
        }

        //服务项目
        else if (countNumbers.getCountType()==4){
            //所有服务项目
            if (countNumbers.getCountId()==null){
                /**
                 * 获得名字
                 */
                List<Lesson> lessonList = lessonMapper.selectAll();
                List<String> namelist = new LinkedList<>();
                for (Lesson lesson:lessonList){
                    namelist.add(lesson.getLessonName());
                }
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                if (ordersList1!=null)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                for (Lesson lesson:lessonList){

                    CountOrgOrders countOrgOrders = new CountOrgOrders();
                    List<Orders> ordersList3 = new LinkedList<>();
                    for (Orders orders:ordersList){

                        if (orders.getLessonId()==lesson.getLessonId())
                            ordersList3.add(orders);
                    }
                    List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList3);
                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lesson.getLessonName());
                    countOrgOrdersList.add(countOrgOrders);
                }
                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
            else if (countNumbers.getCountId()!=null){
                /**
                 * 获得名字
                 */
                List<String> namelist = new LinkedList<>();
                String name = lessonMapper.selectByPrimaryKey(countNumbers.getCountId()).getLessonName();
                namelist.add(name);
                countDa.setNameList(namelist);


                /**
                 * 获得时间
                 * 一周的所有时间
                 */
                List<String> dateList = GetEveryDate.dateToWeek(countOders.getDate());
                countDa.setDateList(dateList);

                /**
                 * 查询所有订单
                 */
                //查询到的所有订单
                List<Orders> ordersList2 = new LinkedList<>();
                countOders.setLessonId(countNumbers.getCountId());
                List<Orders> ordersList1 = ordersMapper.selectInWeeKByLessonId(countOders);
                if (ordersList1.size()>0)
                {
                    for(int i=0;i<ordersList1.size();i++)
                    {
                        Orders orders = ordersList1.get(i);
                        if (orders.getLessonId()==-1)
                        {
                            orders.setLessonName("线下支付");
                        }
                        else
                            orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                        ordersList2.add(orders);

                    }
                }
                List<Orders> ordersList =ScreenByAgeAndPriceAndPayType(ordersList2,countNumbers);
                countDa.setOrdersList(ordersList);




                /**
                 * 获得所有订单成交量
                 */
                List<CountOrgOrders> countOrgOrdersList =new LinkedList<>();
                Lesson lesson = lessonMapper.selectByPrimaryKey(countNumbers.getCountId());

                    CountOrgOrders countOrgOrders = new CountOrgOrders();


                    List<Integer> integerList =CountOrdersNumberByDays.getArray(dateList,ordersList);
                    countOrgOrders.setData(integerList);
                    countOrgOrders.setType("line");
                    countOrgOrders.setName(lesson.getLessonName());
                    countOrgOrdersList.add(countOrgOrders);

                countDa.setCountOrgOrdersList(countOrgOrdersList);

                return Message.success(null).add(countDa);
            }
        }

        return null;
    }

    public List<Orders> ScreenByAgeAndPriceAndPayType(List<Orders> ordersList,CountNumbers countNumbers){


        List<Orders> ordersList1 = ScreenByAge(ordersList,countNumbers);
        List<Orders> ordersList2 = ScreenByPrice(ordersList1,countNumbers);
       List<Orders> ordersList3 = ScreenByPayType(ordersList2,countNumbers);


        return ordersList3;
    }

    public List<Orders> ScreenByAge(List<Orders> ordersList,CountNumbers countNumbers){

        List<Orders> ordersList1 = new LinkedList<>();


        //年龄区间只输入最低年龄或者都输入筛选
        if (countNumbers.getMinAge()!=null)
        {
            if (countNumbers.getMaxAge()==null)
            {
                for (Orders orders:ordersList)
                {
                    int Age = IdcardUtil.getAgeByIdCard(classUserMapper.selectByPrimaryKey(orders.getUserId()).getStuIdCard());
                    if (Age>=countNumbers.getMinAge())
                        ordersList1.add(orders);
                }
                return ordersList1;
            }

            else if (countNumbers.getMaxAge()!=null)
            {
                for (Orders orders:ordersList)
                {

                    int Age = IdcardUtil.getAgeByIdCard(classUserMapper.selectByPrimaryKey(orders.getUserId()).getStuIdCard());
                    if (Age>=countNumbers.getMinAge()&&Age<=countNumbers.getMaxAge())
                        ordersList1.add(orders);
                }
                return ordersList1;
            }
        }

        //年龄区间只输入最高年龄筛选
        else if (countNumbers.getMaxAge()!=null&&countNumbers.getMinAge()==null)
        {
            for (Orders orders:ordersList)
            {
                int Age = IdcardUtil.getAgeByIdCard(classUserMapper.selectByPrimaryKey(orders.getUserId()).getStuIdCard());
                if (Age<=countNumbers.getMaxAge())
                    ordersList1.add(orders);
            }
            return ordersList1;
        }



        return ordersList;
    }

    public List<Orders> ScreenByPrice(List<Orders> ordersList,CountNumbers countNumbers){

        List<Orders> ordersList1 = new LinkedList<>();
        //价格区间只输入最低价格或者都输入筛选
        if (countNumbers.getMinprice()!=null)
        {
            if (countNumbers.getMaxprice()==null)
            {
                for (Orders orders:ordersList)
                {

                    int price = orders.getTotalPrice().multiply(BigDecimal.valueOf(1L)).intValue()/100;

                    if (price>=countNumbers.getMinprice()){
                        System.out.println(price);
                        ordersList1.add(orders);
                    }
                }
                return ordersList1;
            }else if (countNumbers.getMaxprice()!=null)
            {
                for (Orders orders:ordersList)
                {

                    int price = orders.getTotalPrice().multiply(BigDecimal.valueOf(1L)).intValue()/100;
                    if (price>=countNumbers.getMinprice()&&price<=countNumbers.getMaxprice()){
                        ordersList1.add(orders);
                    }
                }
                return ordersList1;
            }
        }
        //价格区间只输入最高价格筛选
        if (countNumbers.getMaxprice()!=null&&countNumbers.getMinprice()==null)
        {
            for (Orders orders:ordersList)
            {

                int price = orders.getTotalPrice().multiply(BigDecimal.valueOf(1L)).intValue()/100;
                if (price<=countNumbers.getMaxprice()){
                    ordersList1.add(orders);
                }
            }
            return ordersList1;
        }
        return ordersList;
    }

    public List<Orders> ScreenByPayType(List<Orders> ordersList,CountNumbers countNumbers){

        List<Orders> ordersList1 = new LinkedList<>();

        //支付方式筛选
        if (countNumbers.getPaytype()!=null)
            if (countNumbers.getPaytype()==0)
            {

                for (Orders orders:ordersList)
                {

                    if (orders.getPayType()==0)
                        ordersList1.add(orders);
                }
                return ordersList1;

            }else if (countNumbers.getPaytype()==1)
            {
                for (Orders orders:ordersList)
                {
                    if (orders.getPayType()==1)
                        ordersList1.add(orders);
                }
                return ordersList1;


            }else if (countNumbers.getPaytype()==2)
            {
                for (Orders orders:ordersList)
                {
                    if (orders.getPayType()==2)
                       ordersList1.add(orders);
                }
                return ordersList1;
            }



        return ordersList;
    }

    @Override
    public Message getExcel(int orgId, int campusId, int timetype, String searchdate) throws ParseException {
        CountOders countOders = new CountOders();
        if (searchdate!=null)
        {
            SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(searchdate);
            countOders.setDate(date);
        }else {
            countOders.setDate(new Date());
        }
        List<Orders> ordersList = new LinkedList<>();
        //接口什么都没传，就返回所有的机构，如[‘求道科技’,’红黄蓝学校’……]
        if (orgId==-999)
        {
            if (campusId==-999)
            {
                //获得所有机构名称
                List<Organization> organizationList = organizationMapper.selectAll();
                List<String> orgNameList = new LinkedList<>();
                for (int i=0;i<organizationList.size();i++)
                {
                    orgNameList.add(organizationList.get(i).getOrgName());
                }


                //1是周
                if (timetype==1)
                {


                    //查询到的所有订单

                    List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }


                }
                //2是月
                else if (timetype==2)
                {


                    //查询到的所有订单

                    List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }

                }
                //3是季
                else if (timetype==3)
                {
                    //一季的所有时间
                    List<String> dateList = GetEveryDate.getQuarterByMonth(countOders.getDate());

                    //查询到的所有订单

                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }



                }
                //4是年
                else if (timetype==4)
                {

                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }

                }

            }
        }

        //传了机构id（orgId），返回该机构下的分支机构
        else if (orgId!=-999)
        {
            if (campusId==-999)
            {
                List<Campus> campusList = campusMapper.selectByOrgId(orgId);
                //1是周
                if (timetype==1)
                {
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());


                    List<Orders> ordersList1 = ordersMapper.selectInWeeK(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }





                }
                //2是月
                else if (timetype==2)
                {
                    //查询所有分支机构名称
                    List<String> capmusNameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        String campusName= campusList.get(i).getCampusName();
                        capmusNameList.add(campusName);
                    }
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());



                    List<Orders> ordersList1 = ordersMapper.selectInMonth(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }

                }
                //3是季
                else if (timetype==3)
                {
                    //查询所有分支机构名称
                    List<String> capmusNameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        String campusName= campusList.get(i).getCampusName();
                        capmusNameList.add(campusName);
                    }
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());



                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }

                }
                //4是年
                else if (timetype==4)
                {
                    //查询所有分支机构名称
                    List<String> capmusNameList = new LinkedList<>();
                    for (int i=0;i<campusList.size();i++)
                    {
                        String campusName= campusList.get(i).getCampusName();
                        capmusNameList.add(campusName);
                    }
                    countOders.setOrgName(organizationMapper.selectByPrimaryKey(orgId).getOrgName());



                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }

                }

            }

            //传了orgId和campusId，返回该分支机构的所有服务项目
            if (campusId!=-999)
            {
                List<Lesson> lessonList = lessonMapper.selectByCampus(campusId);

                //1是周
                if (timetype==1)
                {

                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());




                    List<Orders> ordersList1 = ordersMapper.selectInWeeKInCampus(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }


                }
                //2是月
                else if (timetype==2)
                {
                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                    List<Orders> ordersList1 = ordersMapper.selectInWeeKInCampus(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }



                }
                //3是季
                else if (timetype==3)
                {
                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());



                    List<Orders> ordersList1 = ordersMapper.selectInQuarter(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }




                }
                //4是年
                else if (timetype==4)
                {
                    countOders.setCampusName(campusMapper.selectByPrimaryKey(campusId).getCampusName());

                    List<Orders> ordersList1 = ordersMapper.selectInYear(countOders);
                    if (ordersList1!=null)
                    {
                        for(int i=0;i<ordersList1.size();i++)
                        {
                            Orders orders = ordersList1.get(i);
                            if (orders.getLessonId()==-1)
                            {
                                orders.setLessonName("线下支付");
                            }
                            else
                                orders.setLessonName(lessonMapper.selectByPrimaryKey(orders.getLessonId()).getLessonName());
                            ordersList.add(orders);

                        }
                    }

                }

            }
        }

        ArrayList rows = new ArrayList<>();
        for (int i=0;i<ordersList.size();i++)
        {
            Orders orders =ordersList.get(i);
            Map<String,Object> row =new LinkedHashMap<>();
            row.put("序号",i+1);
            row.put("订单编号",orders.getId());
            row.put("会员手机号",orders.getUserPhone());
            row.put("会员姓名",orders.getUserName());
            row.put("机构名称",orders.getOrgName());
            row.put("分支机构名称",orders.getCampusName());
            row.put("服务项目",orders.getLessonName());
            row.put("支付时间",orders.getPayTime());
            if (orders.getPayType()==0)
            {
                row.put("支付方式","银联支付");
            }
            else if (orders.getPayType()==1)
            {
                row.put("支付方式","分期支付");
            }
            else if (orders.getPayType()==2)
            {
                row.put("支付方式","微信支付");
            }

            rows.add(row);
        }
        ArrayList<Map<String,Object>> allrows = CollUtil.newArrayList(rows);
        // 通过工具类创建writer
        System.out.println(globalConfig.globalFilePath);
        ExcelWriter writer = ExcelUtil.getWriter(globalConfig.globalFilePath+"订单数据表.xlsx");
        // 合并单元格后的标题行，使用默认标题样式
        //writer.merge(rows.size() - 1, "志愿填报");
        // 一次性写出内容，使用默认样式，强制输出标题
        writer.write(allrows, true);
        // 关闭writer，释放内存
        writer.close();
        String returnUrl=globalConfig.hostUrl+"resource/"+"订单数据表.xlsx";

        return Message.success(null).add(returnUrl);
    }

    public Message orgCount(String orgName){
        int orgNum = ordersMapper.countByOrgNamefortj(orgName);
        int orgFenNum = ordersMapper.countByOrgNameAndPayType(orgName);
        CountNumber1 countNumber1 = new CountNumber1();
        countNumber1.setAllnumber(orgNum);
        countNumber1.setFenqinumber(orgFenNum);
        countNumber1.setZhijienumber(orgNum-orgFenNum);
        return Message.success(null).add(countNumber1);
    }

    @Override
    public Message coutconsoleUserorder(int userid, String date1, String date2) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date11 = simpleDateFormat.parse(date1);
        Date date22 = simpleDateFormat.parse(date2);
        List<Orders> AllordersList = ordersMapper.selectByReferenceIdAndPayTime(userid,date11,date22);
        double allprice=0;
        int allcount=0;
        int kuaiJiecount=0;
        double kuaiJieprice=0;
        int wxcount=0;
        double wxprice=0;
        for (Orders orders : AllordersList){
            allprice = allprice+orders.getTotalPrice().doubleValue()/100;
            allcount++;
            if(orders.getPayType()==0){
                kuaiJieprice = kuaiJieprice+orders.getTotalPrice().doubleValue()/100;
                kuaiJiecount++;
            }
            if(orders.getPayType()==2){
                wxprice = wxprice+orders.getTotalPrice().doubleValue()/100;
                wxcount++;
            }
        }
        HashMap hashMap = new HashMap();
        hashMap.put("ALLmoney",allprice);
        hashMap.put("ALLcount",allcount);
        List<Orders> fenqiordersList = ordersMapper.selectByReferenceIdAndPayTypeAndPayTime(userid,1,date11,date22);
        double fenqiprice=0;
        int fenqicount=0;
        for (Orders orders : fenqiordersList){
            fenqiprice = fenqiprice+orders.getTotalPrice().doubleValue()/100;
            fenqicount++;
        }
        hashMap.put("fenqiprice",fenqiprice);
        hashMap.put("fenqicount",fenqicount);
        hashMap.put("zhijieqiprice",allprice-fenqiprice);
        hashMap.put("zhijieqicount",allcount-fenqicount);
        hashMap.put("kuaiJiecount",kuaiJiecount);
        hashMap.put("kuaiJieprice",kuaiJieprice);
        hashMap.put("wxcount",wxcount);
        hashMap.put("wxprice",wxprice);
        return Message.success(null).add(hashMap);
    }

    @Override
    public Message coutconsoleUserorder2(int userid, String date1, String date2) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date11 = simpleDateFormat.parse(date1);
        Date date22 = simpleDateFormat.parse(date2);
        ConsoleUser consoleUser = consoleUserMapper.selectByPrimaryKey(userid);
        List<HashMap> mapList = new ArrayList<>();
        List<Organization> organizationList = organizationMapper.selectByReferenceId(userid);
        for (Organization organization:organizationList){
            List<Campus> campusList = campusMapper.selectByOrgId(organization.getOrgId());
            for (Campus campus:campusList){
                List<Orders> AllordersList = ordersMapper.selectByCampusNameAndPayTime(campus.getCampusName(),date11,date22);
                double allprice=0;
                int allcount=0;
                int kuaiJiecount=0;
                double kuaiJieprice=0;
                int wxcount=0;
                double wxprice=0;
                for (Orders orders : AllordersList){
                    allprice = allprice+orders.getTotalPrice().doubleValue()/100;
                    allcount++;
                    if(orders.getPayType()==0){
                        kuaiJieprice = kuaiJieprice+orders.getTotalPrice().doubleValue()/100;
                        kuaiJiecount++;
                    }
                    if(orders.getPayType()==2){
                        wxprice = wxprice+orders.getTotalPrice().doubleValue()/100;
                        wxcount++;
                    }
                }
                HashMap hashMap = new HashMap();
                hashMap.put("UserId",userid);
                hashMap.put("RealName",consoleUser.getRealname());
                hashMap.put("OrgName",organization.getOrgName());
                hashMap.put("CampusName",campus.getCampusName());
                hashMap.put("ALLmoney",allprice);
                hashMap.put("ALLcount",allcount);
                List<Orders> fenqiordersList = ordersMapper.selectByCampusNameAndPayTimeAndPayType(campus.getCampusName(),date11,date22,1);
                double fenqiprice=0;
                int fenqicount=0;
                for (Orders orders : fenqiordersList){
                    fenqiprice = fenqiprice+orders.getTotalPrice().doubleValue()/100;
                    fenqicount++;
                }
                hashMap.put("fenqiprice",fenqiprice);
                hashMap.put("fenqicount",fenqicount);
                hashMap.put("zhijieqiprice",allprice-fenqiprice);
                hashMap.put("zhijieqicount",allcount-fenqicount);
                hashMap.put("kuaiJiecount",kuaiJiecount);
                hashMap.put("kuaiJieprice",kuaiJieprice);
                hashMap.put("wxcount",wxcount);
                hashMap.put("wxprice",wxprice);
                mapList.add(hashMap);
            }
        }

        return Message.success(null).add(mapList);
    }

    @Override
    public Message coutzhixiaconsoleUserorder(int userid, String date1, String date2) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date11 = simpleDateFormat.parse(date1);
        Date date22 = simpleDateFormat.parse(date2);
        ConsoleUser consoleUser = consoleUserMapper.selectByPrimaryKey(userid);
        if (consoleUser.getSubordinateId()!=null)
        {
            String[] userids = consoleUser.getSubordinateId().split(";");
            List<Map> mapList = new LinkedList<>();
            for (String userid2:userids){
                List<Orders> AllordersList = ordersMapper.selectByReferenceIdAndPayTime(Integer.parseInt(userid2),date11,date22);
                double allprice=0;
                int allcount=0;
                int kuaiJiecount=0;
                double kuaiJieprice=0;
                int wxcount=0;
                double wxprice=0;
                for (Orders orders : AllordersList){
                    allprice = allprice+orders.getTotalPrice().doubleValue()/100;
                    allcount++;
                    if(orders.getPayType()==0){
                        kuaiJieprice = kuaiJieprice+orders.getTotalPrice().doubleValue()/100;
                        kuaiJiecount++;
                    }
                    if(orders.getPayType()==2){
                        wxprice = wxprice+orders.getTotalPrice().doubleValue()/100;
                        wxcount++;
                    }
                }
                HashMap hashMap = new HashMap();
                hashMap.put("ALLmoney",allprice);
                hashMap.put("ALLcount",allcount);
                List<Orders> fenqiordersList = ordersMapper.selectByReferenceIdAndPayTypeAndPayTime(Integer.parseInt(userid2),1,date11,date22);
                double fenqiprice=0;
                int fenqicount=0;
                for (Orders orders : fenqiordersList){
                    fenqiprice = fenqiprice+orders.getTotalPrice().doubleValue()/100;
                    fenqicount++;
                }
                hashMap.put("fenqiprice",fenqiprice);
                hashMap.put("fenqicount",fenqicount);
                hashMap.put("zhijieqiprice",allprice-fenqiprice);
                hashMap.put("zhijieqicount",allcount-fenqicount);
                hashMap.put("dailiren",consoleUserMapper.selectByPrimaryKey(Integer.parseInt(userid2)));
                hashMap.put("kuaiJiecount",kuaiJiecount);
                hashMap.put("kuaiJieprice",kuaiJieprice);
                hashMap.put("wxcount",wxcount);
                hashMap.put("wxprice",wxprice);
                mapList.add(hashMap);
            }
            return Message.success(null).add(mapList);
        }
        return Message.success("您旗下没有其他代理人！");


    }

    /**
     * 根据campusname返回
     * @param userid
     * @param date1
     * @param date2
     * @return
     * @throws ParseException
     */
    @Override
    public Message coutzhixiaconsoleUserorder2(int userid, String date1, String date2) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date11 = simpleDateFormat.parse(date1);
        Date date22 = simpleDateFormat.parse(date2);
        ConsoleUser consoleUser = consoleUserMapper.selectByPrimaryKey(userid);
        if (consoleUser.getSubordinateId()==null){
            return Message.success("您旗下没有其他代理人！");
        }
        else{
            String[] userids = consoleUser.getSubordinateId().split(";");
            List<Map> mapList = new LinkedList<>();
            for (String userid2:userids){
                ConsoleUser consoleUser2 = consoleUserMapper.selectByPrimaryKey(Integer.parseInt(userid2));
                List<Organization> organizationList = organizationMapper.selectByReferenceId(Integer.parseInt(userid2));
                for (Organization organization:organizationList){
                    List<Campus> campusList = campusMapper.selectByOrgId(organization.getOrgId());
                    for (Campus campus:campusList){
                        List<Orders> AllordersList = ordersMapper.selectByCampusNameAndPayTime(campus.getCampusName(),date11,date22);
                        double allprice=0;
                        int allcount=0;
                        int kuaiJiecount=0;
                        double kuaiJieprice=0;
                        int wxcount=0;
                        double wxprice=0;
                        for (Orders orders : AllordersList){
                            allprice = allprice+orders.getTotalPrice().doubleValue()/100;
                            allcount++;
                            if(orders.getPayType()==0){
                                kuaiJieprice = kuaiJieprice+orders.getTotalPrice().doubleValue()/100;
                                kuaiJiecount++;
                            }
                            if(orders.getPayType()==2){
                                wxprice = wxprice+orders.getTotalPrice().doubleValue()/100;
                                wxcount++;
                            }
                        }
                        HashMap hashMap = new HashMap();
                        hashMap.put("UserId",userid2);
                        hashMap.put("RealName",consoleUser2.getRealname());
                        hashMap.put("OrgName",organization.getOrgName());
                        hashMap.put("CampusName",campus.getCampusName());
                        hashMap.put("ALLmoney",allprice);
                        hashMap.put("ALLcount",allcount);
                        List<Orders> fenqiordersList = ordersMapper.selectByCampusNameAndPayTimeAndPayType(campus.getCampusName(),date11,date22,1);
                        double fenqiprice=0;
                        int fenqicount=0;
                        for (Orders orders : fenqiordersList){
                            fenqiprice = fenqiprice+orders.getTotalPrice().doubleValue()/100;
                            fenqicount++;
                        }
                        hashMap.put("fenqiprice",fenqiprice);
                        hashMap.put("fenqicount",fenqicount);
                        hashMap.put("zhijieqiprice",allprice-fenqiprice);
                        hashMap.put("zhijieqicount",allcount-fenqicount);
                        hashMap.put("kuaiJiecount",kuaiJiecount);
                        hashMap.put("kuaiJieprice",kuaiJieprice);
                        hashMap.put("wxcount",wxcount);
                        hashMap.put("wxprice",wxprice);
                        mapList.add(hashMap);
                    }
                }
            }


            return Message.success(null).add(mapList);

        }

    }

    @Override
    public Message coutallconsoleUserorder(String date1, String date2) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date11 = simpleDateFormat.parse(date1);
        Date date22 = simpleDateFormat.parse(date2);
        List<ConsoleUser> consoleUsers = consoleUserMapper.selectByUserGroup1(2);
        List<Map> mapList = new LinkedList<>();
        for (ConsoleUser consoleUser:consoleUsers){
            int userid2 = consoleUser.getUserId();
            List<Orders> AllordersList = ordersMapper.selectByReferenceIdAndPayTime(userid2,date11,date22);
            double allprice=0;
            int allcount=0;
            int kuaiJiecount=0;
            double kuaiJieprice=0;
            int wxcount=0;
            double wxprice=0;
            for (Orders orders : AllordersList){
                allprice = allprice+orders.getTotalPrice().doubleValue()/100;
                allcount++;

                if(orders.getPayType()==0){
                    kuaiJieprice = kuaiJieprice+orders.getTotalPrice().doubleValue()/100;
                    kuaiJiecount++;
                }
                if(orders.getPayType()==2){
                    wxprice = wxprice+orders.getTotalPrice().doubleValue()/100;
                    wxcount++;
                }
            }
            HashMap hashMap = new HashMap();
            hashMap.put("ALLmoney",allprice);
            hashMap.put("ALLcount",allcount);
            List<Orders> fenqiordersList = ordersMapper.selectByReferenceIdAndPayTypeAndPayTime(userid2,1,date11,date22);
            double fenqiprice=0;
            int fenqicount=0;
            for (Orders orders : fenqiordersList){
                fenqiprice = fenqiprice+orders.getTotalPrice().doubleValue()/100;
                fenqicount++;
            }
            hashMap.put("fenqiprice",fenqiprice);
            hashMap.put("fenqicount",fenqicount);
            hashMap.put("zhijieqiprice",allprice-fenqiprice);
            hashMap.put("zhijieqicount",allcount-fenqicount);
            hashMap.put("dailiren",consoleUser);
            hashMap.put("kuaiJiecount",kuaiJiecount);
            hashMap.put("kuaiJieprice",kuaiJieprice);
            hashMap.put("wxcount",wxcount);
            hashMap.put("wxprice",wxprice);

            mapList.add(hashMap);
        }
        return Message.success(null).add(mapList);
    }

    @Override
    public Message coutallconsoleUserorder2(String date1, String date2) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date11 = simpleDateFormat.parse(date1);
        Date date22 = simpleDateFormat.parse(date2);
        List<ConsoleUser> consoleUsers = consoleUserMapper.selectByUserGroup1(2);
        List<Map> mapList = new LinkedList<>();
        for (ConsoleUser consoleUser:consoleUsers){
            List<Organization> organizationList = organizationMapper.selectByReferenceId(consoleUser.getUserId());
            for (Organization organization:organizationList){
                List<Campus> campusList = campusMapper.selectByOrgId(organization.getOrgId());
                for (Campus campus:campusList){
                    List<Orders> AllordersList = ordersMapper.selectByCampusNameAndPayTime(campus.getCampusName(),date11,date22);
                    double allprice=0;
                    int allcount=0;
                    int kuaiJiecount=0;
                    double kuaiJieprice=0;
                    int wxcount=0;
                    double wxprice=0;
                    for (Orders orders : AllordersList){
                        allprice = allprice+orders.getTotalPrice().doubleValue()/100;
                        allcount++;
                        if(orders.getPayType()==0){
                            kuaiJieprice = kuaiJieprice+orders.getTotalPrice().doubleValue()/100;
                            kuaiJiecount++;
                        }
                        if(orders.getPayType()==2){
                            wxprice = wxprice+orders.getTotalPrice().doubleValue()/100;
                            wxcount++;
                        }
                    }
                    HashMap hashMap = new HashMap();
                    hashMap.put("UserId",consoleUser.getUserId());
                    hashMap.put("RealName",consoleUser.getRealname());
                    hashMap.put("OrgName",organization.getOrgName());
                    hashMap.put("CampusName",campus.getCampusName());
                    hashMap.put("ALLmoney",allprice);
                    hashMap.put("ALLcount",allcount);

                    List<Orders> fenqiordersList = ordersMapper.selectByCampusNameAndPayTimeAndPayType(campus.getCampusName(),date11,date22,1);
                    double fenqiprice=0;
                    int fenqicount=0;
                    for (Orders orders : fenqiordersList){
                        fenqiprice = fenqiprice+orders.getTotalPrice().doubleValue()/100;
                        fenqicount++;
                    }
                    hashMap.put("fenqiprice",fenqiprice);
                    hashMap.put("fenqicount",fenqicount);
                    hashMap.put("zhijieqiprice",allprice-fenqiprice);
                    hashMap.put("zhijieqicount",allcount-fenqicount);
                    hashMap.put("kuaiJiecount",kuaiJiecount);
                    hashMap.put("kuaiJieprice",kuaiJieprice);
                    hashMap.put("wxcount",wxcount);
                    hashMap.put("wxprice",wxprice);
                    mapList.add(hashMap);
                }
            }
        }
        return Message.success(null).add(mapList);
    }


    /**
     * time:1234分别是周月季年
     * @return
     */
    @Override
    public Message countFinance (int timeType,Date date) throws ParseException {
        List<CountFinance> countFinanceList = new LinkedList<>();
        List<ConsoleUser> consoleUserList =consoleUserMapper.selectByUserGroup(2);
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM");
        String date1 = simpleDateFormat1.format(date);
        String date2 = simpleDateFormat2.format(date);
        //周
        if(timeType == 1){

            for(ConsoleUser consoleUser:consoleUserList){
                List<Orders> ordersList = ordersMapper.selectByPaytimeInWeek((consoleUser.getUserId()),date1);
                countFinanceList.add(finance(consoleUser,ordersList));
            }
            return Message.success(null).add(countFinanceList);
        }

        //月
        else if(timeType == 2){
            for(ConsoleUser consoleUser:consoleUserList){
                List<Orders> ordersList = ordersMapper.selectByPaytimeInMonth((consoleUser.getUserId()),date2);
                countFinanceList.add(finance(consoleUser,ordersList));
            }
            return Message.success(null).add(countFinanceList);

        }

        //季
        else if(timeType == 3){

            for(ConsoleUser consoleUser:consoleUserList){
                List<Orders> ordersList = ordersMapper.selectByPaytimeInQuarter((consoleUser.getUserId()),date1);
                countFinanceList.add(finance(consoleUser,ordersList));
            }
            return Message.success(null).add(countFinanceList);
        }

        //年
        else if(timeType == 4){
            for(ConsoleUser consoleUser:consoleUserList){
                List<Orders> ordersList = ordersMapper.selectByPaytimeInYear((consoleUser.getUserId()),date1);
                countFinanceList.add(finance(consoleUser,ordersList));
            }
            return Message.success(null).add(countFinanceList);
        }

        //传输值丢失
        else{
            return Message.fail("传输数据出现问题");
        }


    }

    /**
     * 代理人封装类
     * @param consoleUser
     * @param ordersList
     * @return
     */
    public CountFinance finance(ConsoleUser consoleUser,List<Orders> ordersList){
        CountFinance countFinance = new CountFinance();
        countFinance.setAgentId(consoleUser.getUserId().toString());
        countFinance.setAgentName(consoleUser.getUsername());
        int i=0,j=0;
        BigDecimal money=new BigDecimal("0"),moneyByStage=new BigDecimal("0");
        for(Orders orders : ordersList){
            //直接支付
            if(orders.getPayType()==0) {
                money = money.add(orders.getTotalPrice());
                i++;
            }
            //分期支付
            else if(orders.getPayType()==1){
                j++;
                moneyByStage = moneyByStage.add(orders.getTotalPrice());

            }
        }

        /**
         * 个人分佣情况
         */
        BigDecimal gerenfenyong = new BigDecimal("0");
        gerenfenyong = gerenfenyong.add(moneyByStage);                                      //分佣的钱
        int RebateLevel = CalculateAgentsCurrentPersonalRating(consoleUser.getUserId());    //拿到个人的等级
        RebateLevel rebateLevel = rebateLevelMapper.selectByPrimaryKey(RebateLevel);
        BigDecimal bd1 = new BigDecimal("100");
        BigDecimal bd2 = rebateLevel.getRebateLevelRatio();
        BigDecimal bd3 = rebateLevel.getRebateKjpay();
        BigDecimal bd4 = rebateLevel.getRebateWxpay();

        gerenfenyong=gerenfenyong.multiply(bd2.add(bd3).add(bd4));
        gerenfenyong=gerenfenyong.divide(bd1);
        gerenfenyong=gerenfenyong.divide(bd1);

        /**
         * 团队分佣
         */
        BigDecimal tuanduifenyong = new BigDecimal("0");
        tuanduifenyong = tuanduifenyong.add(CalculateAgentsCurrentTeamRatingMoney(consoleUser.getUserId())); //返回的团队等级


        BigDecimal distribution = new BigDecimal("0");
        distribution = distribution.add(gerenfenyong);
        distribution = distribution.add(tuanduifenyong);

        countFinance.setDistribution(distribution);
        countFinance.setCount(i);
        countFinance.setCountByStage(j);
        countFinance.setMoney(money);
        countFinance.setMoneyByStage(moneyByStage);
        countFinance.setOrdersList(ordersList);
        return countFinance;
    }

    /**
     * 计算代理人目前个人等级
     */
    public int CalculateAgentsCurrentPersonalRating(int referenceId){
        List<Orders> ordersList = ordersMapper.selectByReferenceIdAndPayType(referenceId,1);
        BigDecimal fenqimoney = new BigDecimal("0");
        for (Orders orders:ordersList){
            fenqimoney.add(orders.getTotalPrice());
        }
        BigDecimal bd8 = new BigDecimal("100");
        fenqimoney.multiply(bd8);
        List<BigDecimal> AlltotalTradingVolumeList = rebateLevelMapper.selectAlltotalTradingVolume();

        BigDecimal FirstStage = AlltotalTradingVolumeList.get(0);
        BigDecimal SecondStage = AlltotalTradingVolumeList.get(1);
        BigDecimal ThirdStage = AlltotalTradingVolumeList.get(2);
        BigDecimal FourthStage = AlltotalTradingVolumeList.get(3);
        int a = fenqimoney.compareTo(FirstStage);
        if (a==-1){
            return 1;
        }
        else if (a==0){
            return 2;
        }else {
            int b = fenqimoney.compareTo(ThirdStage);
            if (b==-1){
                return 2;
            }
            else if (b==0){
                return 3;
            }
            else {
                int c = fenqimoney.compareTo(FourthStage);
                if (c==-1){
                    return 3;
                }
                else {
                    return 4;
                }
            }
        }

    }

    /**
     * 判断代理人是否属于团队,是的话返回团队等级，不是返回0
     */
    public int CalculateAgentsCurrentTeamRating(int referenceId){
        List<ConsoleUser> consoleUserList =consoleUserMapper.selectByUserGroup(2);
        ConsoleUser consoleUser1 = new ConsoleUser();
        for (ConsoleUser consoleUser:consoleUserList){
            String userids[] = consoleUser.getSubordinateId().split(";");
            for (String userid:userids){
                if (Integer.parseInt(userid)==referenceId){
                    consoleUser1=consoleUser;
                    break;
                }
            }
            if (consoleUser1!=null){
                break;
            }
        }
        if (consoleUser1==null){
            return 0;
        }else{
            BigDecimal amount = new BigDecimal("0");
            String userids2[] = consoleUser1.getSubordinateId().split(";");
            for (String userid:userids2){
                ConsoleUser consoleUser = consoleUserMapper.selectByPrimaryKey(Integer.parseInt(userid));
                List<Orders> fenqiordersList = ordersMapper.selectByReferenceIdAndPayType(Integer.parseInt(userid),1);
                for (Orders orders: fenqiordersList){
                    amount=amount.add(orders.getTotalPrice());
                }
            }
            BigDecimal bd8 = new BigDecimal("100");
            amount = amount.multiply(bd8);
            List<BigDecimal> AlltotalTradingVolumeList = rebateLevelMapper.selectAlltotalTradingVolume();
            BigDecimal FirstStage = AlltotalTradingVolumeList.get(4);  //五级团队
            BigDecimal SecondStage = AlltotalTradingVolumeList.get(5);
            BigDecimal ThirdStage = AlltotalTradingVolumeList.get(6);
            BigDecimal FourthStage = AlltotalTradingVolumeList.get(7);
            int a = amount.compareTo(FirstStage);   // 用来存储判断结果 1是达到等级 0 等于  -1小于...等级
            if (a==-1){
                return 1;
            }
            else if (a==0){
                return 5;
            }else {
                int d = amount.compareTo(SecondStage);
                if (d==-1){
                    return 5;
                }else if (d==0){
                    return 6;
                }
                else {
                int b = amount.compareTo(ThirdStage);
                if (b==-1){
                    return 6;
                }
                else if (b==0){
                    return 7;
                }
                else {
                    int c = amount.compareTo(FourthStage);
                    if (c==-1){
                        return 7;
                    }
                    else {
                        return 8;
                    }
                }
                }
            }

        }
    }

    /**
     * 判断代理人是否属于团队,是的话返回津贴收益，不是返回0
     */
    public BigDecimal CalculateAgentsCurrentTeamRatingMoney(int referenceId){
        BigDecimal all = new BigDecimal("0");
        List<ConsoleUser> consoleUserList =consoleUserMapper.selectByUserGroup(2);
        ConsoleUser consoleUser1 = new ConsoleUser();    //用来判断 是否是团队成员
        for (ConsoleUser consoleUser:consoleUserList){
            if (consoleUser.getSubordinateId()!=null)
            {
            String userids[] = consoleUser.getSubordinateId().split(";");
            for (String userid:userids){
                if (Integer.parseInt(userid)==referenceId){
                    consoleUser1=consoleUser;
                    break;
                }
            }
            }
            if (consoleUser1!=null){
                break;
            }
        }
        if (consoleUser1==null){
            return all;     //没有存储对象,返回 0
        }else{
            BigDecimal amount = new BigDecimal("0");  //用来存储团队分佣价钱
            if (consoleUser1.getSubordinateId()!=null){


            String userids2[] = consoleUser1.getSubordinateId().split(";"); //把组员全部找到存储到 userids2[]
            for (String userid:userids2){
                //ConsoleUser consoleUser = consoleUserMapper.selectByPrimaryKey(Integer.parseInt(userid));
                List<Orders> fenqiordersList = ordersMapper.selectByReferenceIdAndPayType(Integer.parseInt(userid),1);
                for (Orders orders: fenqiordersList){
                    amount=amount.add(orders.getTotalPrice());
                }
            }
            }
            int level =0;
            List<BigDecimal> AlltotalTradingVolumeList = rebateLevelMapper.selectAlltotalTradingVolume();
            BigDecimal FirstStage = AlltotalTradingVolumeList.get(4);
            BigDecimal SecondStage = AlltotalTradingVolumeList.get(5);
            BigDecimal ThirdStage = AlltotalTradingVolumeList.get(6);
            BigDecimal FourthStage = AlltotalTradingVolumeList.get(7);

            int a = amount.compareTo(FirstStage);
            if (a==-1){
                level = 5;
            }
            else if (a==0){
                level = 5;
            }else {
                int d = amount.compareTo(SecondStage);
                if (d==-1){
                    level = 5;
                }else if (d==0){
                    level = 6;
                }
                else {
                    int b = amount.compareTo(ThirdStage);
                    if (b==-1){
                        level = 6;
                    }
                    else if (b==0){
                        level = 7;
                    }
                    else {
                        int c = amount.compareTo(FourthStage);
                        if (c==-1){
                            level = 7;
                        }
                        else {
                            level = 8;
                        }
                    }
                }
            }
            RebateLevel rebateLevel = rebateLevelMapper.selectByPrimaryKey(level); //找到对应等级的所有数据
            BigDecimal bd1 = new BigDecimal("100");
            BigDecimal bd2 = rebateLevel.getRebateTeamRatio();    //拿到等级的团队分佣比例

            amount=amount.multiply(bd2);

            amount=amount.divide(bd1);

            amount=amount.divide(bd1);
            return amount;
        }
    }








}
